var url = location.pathname.substring(1);
if (url.toLowerCase().indexOf("checkin") >= 0) { // This is the Check-In page..
    String.prototype.toProperCase = function() {
        return this.trim().toLowerCase().replace("'", "\\'").replace(/\b[A-z]/g, function(e) {
            return e.toUpperCase()
        })
    };
    var form = document.getElementById("mainform2");
    for (var i = 0; i < form.elements.length; i++) {
        var e = form.elements[i];
        // Make values Proper Case
        if (e.type === "text" && (/Name/.test(e.name) && e.size == 25 || /City/.test(e.name) && e.size == 35 || /Street/.test(e.name) && e.size == 35 || /Notes/.test(e.name) && e.size == 20)) {
            e.value = e.value.toProperCase()
        }
        // Fix initials
        if (e.type === "text" && /Name/.test(e.name) && e.size == 25) {
            e.value = e.value.replace(/(^\w)( )/gim, "$1" + "." + "$2"); // Start of string, word character, space. Needs period.
            e.value = e.value.replace(/(,)( )(\w$)/gim, "$1" + "$2" + "$3" + "."); // Comma, space, word character, end of string. Needs period.
            e.value = e.value.replace(/(\w)( )(\w$)/gim, "$1" + "," + "$2" + "$3" + "."); // Word character, space, word character, end of string. Needs comma and period.
            e.value = e.value.replace(/(\w)( )(\w)(\.$)/gim, "$1" + "," + "$2" + "$3" + "$4"); // Word character, space, word character, period, end of string. Needs comma.
        }
        // Fix phone numbers
        if (e.type === "text" && (/Phone/.test(e.name) && e.size == 15)) {
            e.value = e.value.replace(/\D+/g, ''); // Get digits only, dump other chars
            var len = e.value.length;
            if (len > 4) { // ###-####
                e.value = e.value.substring(0, len - 4) + '-' + e.value.substring(len - 4);
            };
            if (len > 7) { // ###-###-####
                e.value = e.value.substring(0, len - 7) + '-' + e.value.substring(len - 7);
            };
            if (len > 10) { // #-###-###-####
                e.value = e.value.substring(0, len - 10) + '-' + e.value.substring(len - 10);
            };
        }
    }
    var checkboxes = document.getElementsByName("Edit[]");
    for (var i = 0; i < checkboxes.length; i++) {
        if (checkboxes[i].checked == false) {
            checkboxes[i].click(); // Click it to activate onClick event
        };
        checkboxes[i].checked = true; // And make sure it's checked
    }
} else if (url.toLowerCase().indexOf("printpreview2") >= 0) { // This is the Print page..
    var td = document.getElementsByTagName('td')
    for (var y = 0; y < td.length; y++) {
        var textContent = td[y].textContent
        if ((textContent.toLowerCase().indexOf("fr") > -1 || textContent.toLowerCase().indexOf("en") > -1 || textContent.toLowerCase().indexOf("bul") > -1 || textContent.toLowerCase().indexOf("rom") > -1 || textContent.toLowerCase().indexOf("ukr") > -1 || textContent.toLowerCase().indexOf("hun") > -1) && td[y].colSpan == 2) {
            td[y].parentNode.setAttribute('style', 'background-color:rgb(230,230,230);');
        } else if ((textContent.toLowerCase().indexOf("do not") > -1) && td[y].colSpan == 2  && td[y].previousSibling.textContent != "DNC") {
            td[y].parentNode.setAttribute('style', 'background-color:rgb(230,200,200);font-style:italic');
        }
    }
} else {
    alert("Ain't nothing to do here...")
}